package com.itheima.threaddemo14;

public class Cooker extends Thread{
    private Desk desk;

    public Cooker(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (desk.getLock()) {
                if (desk.getCount() == 0) {
                    break;
                }
                if (!desk.isFlag()) {
                    // 生产
                    System.out.println("厨师正在生产汉堡包");
                    desk.setFlag(true);
                    desk.getLock().notifyAll();
                } else {
                    // 等待
                    try {
                        desk.getLock().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
